//package com.emar.adx.yiqifa.thread;
//
//import com.emar.adx.yiqifa.entity.Feedback;
//import com.emar.adx.yiqifa.service.FeedbackService;
//import com.emar.adx.yiqifa.util.ConfigurationFactory;
//import com.emar.adx.yiqifa.util.FunctionUtil;
//import com.emar.adx.yiqifa.util.RandomUtil;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * Created by Administrator on 2015/11/18.
// */
//public class FeedbackTestThread extends Thread {
//
//    private Logger logger = LoggerFactory.getLogger(FeedbackTestThread.class);
//
//    private FeedbackService feedbackService = null;
//
//    public void setFeedbackService(FeedbackService feedbackService) {
//        this.feedbackService = feedbackService;
//    }
//
//    private int total = 0;
//    private String tables = "";
//    private List<String> dataList = new ArrayList<String>();
//
//    public void setTotal(int total) {
//        this.total = total;
//    }
//
//    public void setTables(String tables) {
//        this.tables = tables;
//    }
//
//    public void setDataList(List<String> dataList) {
//        this.dataList = dataList;
//    }
//
//    @Override
//    public void run() {
//        String[] tableArr = tables.split(",");
//        int total = dataList.size();
//
//        try {
//            while (true) {
//
//                    long sleepTime = RandomUtil.random(10, 10000);
//
//                    //偶数则查有效key
//                    boolean isValidSearch = RandomUtil.random(0,10000)%2 == 0 ? true:false;
//
//                    //从csv中按key查找
//                    if(isValidSearch){
//                        //从数据库中获取一条存在的数据
//                        int offset = RandomUtil.random(0, total - 1);
//                        String feedbackKey = dataList.get(offset);
//                        logger.info("csv get valid feedback key = " + feedbackKey + " offset = " + offset);
//                        long start = System.currentTimeMillis();
//                        for(int t =0;t<tableArr.length;t++){
//                            String tableName = tableArr[t];
//                            logger.info("table = " + tableName + " start find valid key = " + feedbackKey);
//                            Feedback feedback1 = feedbackService.findOneByKey(tableName, feedbackKey);
//                            long end = System.currentTimeMillis();
//                            if(feedback1!=null){
//                                logger.info("table = " + tableName + " end find valid key = " + feedback1.getFeedbackKey() + ",value="+feedback1.getFeedbackValue()+" cost time = " + (end - start));
//                                break;
//                            }else {
//                                logger.info("table = " + tableName + " not find valid key = " + feedbackKey + " cost time = " + (end - start));
//                                continue;
//                            }
//                        }
//                    }else {
//                        //随机生成一个无效的key
//                        String invalidKey = RandomUtil.getRandomString(20);
//                        long start = System.currentTimeMillis();
//                        for(int t =0;t<tableArr.length;t++){
//                            String tableName = tableArr[t];
//                            logger.info("table = " + tableName + " start find invlid key = " + invalidKey);
//                            Feedback feedback1 = feedbackService.findOneByKey(tableName, invalidKey);
//                            long end = System.currentTimeMillis();
//                            logger.info("table = " + tableName + " end find invlid key = " + invalidKey + " cost time = " + (end - start));
//                        }
//
//                    }
//
//                    logger.info("thread id[" + this.getId() + "] sleep time " + sleepTime);
//                    Thread.sleep(sleepTime);
//                }
//
////            }
//
//        }catch (Exception e) {
//            logger.error("thread id[" + this.getId() + "]  error:", e);
//        }
//
//
//    }
//
//
//}
